<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="80px">
         <div class="shuxing">
        <el-form-item label="行政区划" prop="areaId">
          <treeselect
             v-model="queryParams.areaId"
            class="shuxing1"
            :options="deptOptions"
            :normalizer="normalizer"
            placeholder="选择区域"
          />
        </el-form-item>
      </div>
    
      <el-form-item label="主体名称" prop="enterName">
        <el-input
          v-model="queryParams.enterName"
          placeholder="请输入主体名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="农产品" prop="plantType">
        <el-input
          v-model="queryParams.plantType"
          placeholder="请输入农产品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button type="primary" icon="el-icon-plus"  size="mini"  @click="handleAdd" v-hasPermi="['productTestInfo:testInfot:add']">新增</el-button>
        
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
         <el-table-column
        label="序号"
        align="center"
        type="index"
        :index="indexMethod"
        width="80"
      />
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主体名称" align="center" prop="enterName" />
      <el-table-column label="产品名称" align="center" prop="plantType" />
      <el-table-column label="上报日期" align="center" prop="reportingTime" />
      <el-table-column label="追溯码申请数量" align="center" prop="applyCode" />
      <el-table-column label="审核状态" align="center" prop="authStatus" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['certificateInfo:info:edit']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleUpdate(scope.row,1)"
            v-hasPermi="['certificateInfo:info:remove']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改TCertificateInfo对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <div class="add">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" >
         <el-divider content-position="left" class="box-title">追溯信息</el-divider>
        <div class="add-box">
        <el-form-item label="包装产品名称" prop="enterId">
          <el-input v-model="form.productName"   readonly/>
        </el-form-item>
        <el-form-item label="农产品分类代码" prop="productName">
          <el-input v-model="form.productName"  readonly />
        </el-form-item>
         <el-form-item label="主体名称" prop="productName">
          <el-input v-model="form.enterName"   readonly />
        </el-form-item>
       
      
        <el-form-item label="所属区域" prop="applyCode">
            <treeselect
            :aria-disabled="false"
             v-model="form.areaId"
            class="shuxing1"
            :options="deptOptions"
            :normalizer="normalizer"
            placeholder="选择区域"
          />
        </el-form-item>
        <el-form-item label="备案机构" prop="certificateCode">
          <el-input v-model="form.recordName"   readonly/>
        </el-form-item>
        <el-form-item label="上报日期" prop="authContext">
          <el-input v-model="form.reportingTime"   readonly />
        </el-form-item>
        <el-form-item label="追溯码申请数量">
           <el-input v-model="form.applyCode"  readonly />
        </el-form-item>
        </div>
        <el-form-item label="">
           <div class="zhuisu">
              <div class="zhuisu-box">
                  <p class="zhuisu-title">宁夏食用农产品合格证---追溯凭证</p>
                  <p class="zhui-bianma">合格证编号:{{form.certificateCode}}</p>
                  <div class="zhuisu-box-top">
                    <p>食用农产品名称:{{form.productName}}</p>
                    <p>包装的食品数量(重量):{{form.productPackagedInfo.packageNum}}{{form.productPackagedInfo.packageUnit}}</p>
                    <p>生产者盖章或签名:{{form.plantEnterpriseInfo.enterName}}</p>
                    <p>确保合格的方式:自检合格</p>
                    <p>联系人:{{form.enterContactsInfo.contactsName}}</p>
                    <p>联系方式:{{form.enterContactsInfo.contactsPhone}}</p>
                    <p>上报日期:{{form.reportingTime}}</p>
                    <p>基地地址:{{form.plantEnterpriseInfo.enterAddress}}</p>
                    <div class="zhuisu-box-left">
                         <p class="chengnuo">我承诺对产品质量安全以及合格证真实性负责</p>
                        <p class="el-icon-success">&nbsp;&nbsp;我不使用禁限用农药兽药</p>
                        <p class="el-icon-success">&nbsp;&nbsp;不使用非法添加剂</p>
                        <p class="el-icon-success">&nbsp;&nbsp;遵守农药安全间隔期,兽药休药规定</p>
                        <p class="el-icon-success">&nbsp;&nbsp;销售的食品农产品符合农药兽药残留食品安全国家标准</p>

                    </div>
                  </div>
                  <div class="zhuisu-erwei">
                    <vue-qr :text="downloadData.url" :margin="10" colorDark="#000" colorLight="#fff" :dotScale="1" :logoSrc="downloadData.icon" :logoScale="0.2" :size="200"></vue-qr>
                  </div>
              </div>
             
           </div>
        </el-form-item>
        
        <el-divider content-position="left" class="box-title">质检信息</el-divider>
        <div class="add-box">
             <el-form-item label="质检情况">
           <el-input v-model="form.productTestInfo.qualityNspection"   readonly />
        </el-form-item>
         <el-form-item label="质检单位">
           <el-input v-model="form.productTestInfo.qualityCompany"   readonly />
        </el-form-item>
         <el-form-item label="产品追溯码">
           <el-input v-model="form.productTestInfo.productTraceCode"   readonly />
        </el-form-item>
         <el-form-item label="">
        </el-form-item>
        </div>
         <el-form-item label="质检描述">
           <el-input type="textarea" v-model="form.productTestInfo.qualityDesc" placeholder=""  readonly />
        </el-form-item>
         <el-form-item label="质检结论">
           <el-input type="textarea" v-model="form.productTestInfo.qualityConclusion" placeholder=""  readonly />
        </el-form-item>
         <el-form-item label="附件">
           <div class="photo">
             <img :src="form.productTestInfo.qualityImg" >
           </div>
           <!-- <el-input type="textarea" v-model="form.productTestInfo.qualityImg" placeholder=""  readonly /> -->
        </el-form-item>
          <el-divider></el-divider>
           <el-form-item label="审核内容">
           <el-input  v-model="form.authContext" placeholder=""  />
        </el-form-item>
      </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <span v-show="showif">
        <el-button type="primary" @click="submitForm">通 过</el-button>
        <el-button type="danger" @click="submitForm1">退 回</el-button>
        </span>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo,getTree } from "@/api/certificateInfo/info";

import vueQr from 'vue-qr'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Info",
  components:{Treeselect,vueQr},
  data() {
    return {
      // 二维码
       downloadData: {
                url: 'http://192.168.0.138:80/qrCode',  //需要转化成二维码的网址
        },
      showif:false,
      // 返回的表格，使用html展开
      ss:"",
      // 时间
      value1:"",
      // 树状数
      xingzheng:"请选择",
      deptOptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // TCertificateInfo表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaId: undefined,
        enterName: undefined,
        plantType: undefined,
        enterId: undefined,
        productName: undefined,
        goodPrductType: undefined,
        reportingTime: undefined,
        applyCode: undefined,
        certificateCode: undefined,
        authContext: undefined,
        authStatus: undefined
      },
      // 表单参数
      form: {
        productTestInfo:{},
        productPackagedInfo:{},
        plantEnterpriseInfo:{},enterContactsInfo:{}
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getTree();
  },
  methods: {
    // 序号
    indexMethod(index) {
      return index + 1;
    },
     // 行政区划分列表
    getTree() {
      this.loading = true;
      getTree().then((response) => {
        this.deptOptions = this.handleTree(response.data, "id");
      });
    },
    // 树形
     normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.label,
        children: node.children,
      };
    },
    /** 查询TCertificateInfo列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        enterId: undefined,
        productName: undefined,
        goodPrductType: undefined,
        reportingTime: undefined,
        applyCode: undefined,
        certificateCode: undefined,
        authContext: undefined,
        authStatus: "0",
        productTestInfo:{},
        productPackagedInfo:{},
        plantEnterpriseInfo:{},
        enterContactsInfo:{}
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.value1="";
      this.xingzheng="";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.form={};
      this.reset();
      this.open = true;
      this.title = "产品追溯审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row,str) {
      this.showif=true;
      if(str)
      {
        this.showif=false;
      }
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.form.areaId=response.data.enterArea;
        this.open = true;
        this.downloadData.url= this.downloadData.url+"?id="+id;
        this.title = "产品追溯审核";
      });
    },
    /** 通过按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            let addstatus={
                authContext:this.form.authContext,
                 authStatus:"通过",
                 id:this.form.id,
            }
            updateInfo(addstatus).then(response => {
              if (response.code == 0) {
                this.msgSuccess("审核完成");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    }, /** 退回按钮 */
    submitForm1: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            let addstatus={
                authContext:this.form.authContext,
                 authStatus:"退回",
                 id:this.form.id,
            }
            updateInfo(addstatus).then(response => {
              if (response.code == 0) {
                this.msgSuccess("审核完成");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除TCertificateInfo编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有TCertificateInfo数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.data);
        }).catch(function() {});
    }
  }
};
</script>
<style lang="scss" scoped>
.shuxing
{
   width: 250px;
  float: left;
   .shuxing1{
     width: 150px !important;
    height: 35px;
   }
}
.add .el-form-item{
  width: 100%;
}
.add{
  width: 100%;
  height: 600px;
  overflow-y: auto;
  .el-form .add-box{
    .el-form-item{
  width: 47%;
}
    width: 100%;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    }
}
.box-title .el-divider__text{
  font-size: 20px;
}
.el-dialog__header{
  position: sticky;
  top: 0;
}
.zhuisu{
  width: 100%;
}
.zhuisu-box{
  width: 80%;
  min-width: 900px;
  overflow-x: auto;
  margin: 0 auto;
  p{
    height: 17px;
  }
  .zhuisu-title{
    width: 80%;
    min-width: 600px;
    color: black;
    font-weight: 700;
    font-size: 16px;
    text-align: center;
  }
  .zhuisu-box-top{
     width: 40%;
     min-width: 450px;
     float: left;
  }
  .zhuisu-box-left{
    // margin-left: 10px;
    .chengnuo{
      font-weight: 700;
      color: black;
      font-size: 15px;
    }
    p{
      width: 100%;
      height: 17px;
    }
  }
  .zhuisu-erwei{
     width: 40%;
     min-width: 450px;
    height: 300px;
    // background-color: aqua;
    float: left;
  }
}
.photo img{
  width: 150px;
  height: 150px;
  margin-left: 5px;
}
</style>